package com.jeasonzhao.report.exceptions;

import com.jeasonzhao.report.codes.ReportDictTypes;
import com.jeasonzhao.report.engine.irp.IDictItemsProvider;
import com.jeasonzhao.report.model.ReportDict;
import com.jeasonzhao.report.msg.Message;

@Message(
    {"zh_cn","字典配置错误:{...}"
    ,"en","Dictionary configuration error: {...}"
})
public class DictException extends SQLReportException
{
    private static final long serialVersionUID = 1L;
    public DictException(Object ...objs)
    {
        super(objs);
    }

    public DictException(Throwable t,Object ...objs)
    {
        super(t,objs);
    }

    @Message(
             {"zh_cn","{0}没有配置生成数据的类, 指定的类必须实现接口 {1}"
             ,"en","{0} no data generate-class has been set, the class sould implements {1}"
    })
    public static class NoClassForExternalDict extends DictException
    {
        private static final long serialVersionUID = 1L;
        public NoClassForExternalDict(ReportDict dict)
        {
            super(dict,IDictItemsProvider.class.getName());
        }
    }

    @Message(
        {"zh_cn","{0}没有配置生成字典的唯一标识"
        ,"en","{0} no identifier defined"
    })
    public static class NoIdentifier extends DictException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public NoIdentifier(ReportDict dict)
        {
            super(dict);
        }
    }

    @Message(
        {"zh_cn","{0}没有配置生成数据的SQL"
        ,"en","{0} no SQL has been set"
    })
    public static class NoSQL extends DictException
    {
        private static final long serialVersionUID = 1L;

        public NoSQL(ReportDict dict)
        {
            super(dict);
        }
    }
    @Message(
           {"zh_cn","{0}配置的SQL语句错误，结果字段数量不得少于2个:{1}"
           ,"en","{0} SQL statement error, the amount of columns should be more than 1:{1}"
       })
       public static class SQLColumnNotEnough extends DictException
       {
           private static final long serialVersionUID = 1L;

           public SQLColumnNotEnough(ReportDict dict)
           {
               super(dict,null==dict?null:dict.getSqlStatement());
           }
    }
    @Message(
        {"zh_cn","{0}没有配置生成数据的数据库ID"
        ,"en","{0} no database reference has been set"
    })
    public static class NoDatabase extends DictException
    {
        private static final long serialVersionUID = 1L;

        public NoDatabase(ReportDict dict)
        {
            super(dict);
        }
    }

    @Message(
        {"zh_cn","{0}没有配置生成数据的树形结构图,结构图规则为"
        ,"en","{0} no tree-mapping has been set, the rule is [value of the root node]|"
    })
    public static class NoTreeDefined extends DictException
    {
        private static final long serialVersionUID = 1L;

        public NoTreeDefined(ReportDict dict)
        {
            super(dict);
        }
    }

    @Message(
        {"zh_cn","{0}未知的字典类型{1}"
        ,"en","{0} Unknown dictionary-type {1}"
    })
    public static class UnknownType extends DictException
    {
        private static final long serialVersionUID = 1L;

        public UnknownType(ReportDict dict,ReportDictTypes t)
        {
            super(dict,null == t ? "NULL" : t.toString());
        }
    }

    @Message(
        {"zh_cn","{0}初始化的时候没有初始化任何字典数据"
        ,"en","{0} No dictionary items in this dictionary"
    })
    public static class NoData extends DictException
    {
        private static final long serialVersionUID = 1L;
        public NoData(ReportDict dict)
        {
            super(dict);
        }
    }

    @Message(
        {"zh_cn","{0}执行初始化的SQL语句\"{2}\"的时候出错: {1}"
        ,"en","{0} error when executing SQL statement \"{2}\" : {1}"
    })
    public static class SQLExecutingError extends DictException
    {
        private static final long serialVersionUID = 1L;
        public SQLExecutingError(ReportDict dict,Throwable t)
        {
            super(t,dict,null == t ? "" : t.getMessage(),dict.getSqlStatement());
        }
    }

    @Message(
        {"zh_cn","{0}执行初始化的时候出错 {1},{2}"
        ,"en","{0} error when executing class {1},{2}"
    })
    public static class ExternalExecutingError extends DictException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public ExternalExecutingError(ReportDict dict,Throwable t)
        {
            super(t,dict,null == dict ? "" : dict.getParameter(),null == t ? "" : t.getMessage());
        }
    }

    @Message(
        {"zh_cn","{0}配置的类{1}不正确，类不能转换为{2}"
        ,"en","{0} Configuration Error, can not convert the class {1} to {2}"
    })
    public static class CastError extends DictException
    {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public CastError(ReportDict dict,String strClassName,Class<?> destinationClass)
        {
            super(dict,strClassName
                  ,null == destinationClass ? "[Unknown destination]" : destinationClass.getName());
        }

        public CastError(ReportDict dict,String strClassName,Class<?> destinationClass,Throwable t)
        {
            super(t,dict,strClassName
                  ,null == destinationClass ? "[Unknown destination]" : destinationClass.getName());
        }

    }

}
